package rsb212.num23.ysh.d1016.store;

import java.time.LocalDateTime;
import java.util.Random;
import java.util.Scanner;

public class BookStore {
    static Book[] books=new Book[6];
    static{
        books[0]=new Book(1,"java",50,10);
        books[1]=new Book(2,"C++",40,10);
        books[2]=new Book(3,"PHP",30,10);
        books[3]=new Book(4,"Python",20,10);
        books[4]=new Book(5,"web",20,10);
        books[5]=new Book(6,"mysql",20,10);
    }
    public static void main(String[] args) {
        //显示库中的图书
        show(books);
        //有顾客来购买数
        Person p=new Person("张三");
        Book book=p.buy(books);
        //结算
        count(p,book);

    }
    //显示图书
    public static void show(Book[] books){
        System.out.println("图书编号\t图书名称\t图书价格\t库存");
        for(int i=0;i<books.length;i++){
            System.out.println(books[i].getId()+"\t"+books[i].getName()+"\t"+books[i].getPrice()+"\t"+books[i].getStorage());

        }

    }
    //结算
    public static void count(Person p,Book book){
        System.out.println("请输入购书的数量");
        Scanner sc=new Scanner(System.in);
        int number=sc.nextInt();//购买图书的数量
        //随机数
        Random random=new Random();
        int orderNum=random.nextInt();
        System.out.println("订单编号:"+Math.abs(orderNum));

        System.out.println("购物时间:"+ LocalDateTime.now());
        System.out.println("会员:"+p.getName());

        System.out.println("图书名称"+book.getName()+",单价"+book.getPrice()+",购买数量"+number);
        System.out.println("-------------总计:"+book.getPrice()*number);

    }

}